package com.aspose.cells;

class zawj extends zawe {
   private zagu[] g;
   private int h;
   private int i;
   private boolean j;
   private boolean k;
   private int l;
   private int m;
   private int n;
   private int o;
   private boolean p;
   private boolean q;
   private int r;
   private zagu s;

   public zawj(zagu[] var1, boolean var2, int var3, int var4, int var5, int var6, int var7, zagu var8, int var9, int var10, boolean var11, boolean var12) {
      super(var7, var8, var9, var10, var11, var12);
      this.g = var1;
      this.j = var2;
      this.h = var4;
      this.i = var6;
      this.k = this.h < 2 && this.i < 2;
      this.m = var3;
      this.l = var5;
      this.E();
   }

   zawj(zawj var1) {
      super(var1.b, var1.a, var1.e, var1.f, var1.c, var1.d);
      this.g = var1.g;
      this.h = var1.h;
      this.i = var1.i;
      this.j = var1.j;
      this.k = var1.k;
      this.l = var1.l;
      this.m = var1.m;
      this.n = var1.n;
      this.o = var1.o;
      this.p = var1.p;
      this.q = var1.q;
      this.r = var1.r;
      this.s = var1.s;
   }

   public zahn b(zaay var1) {
      return new zawj(this);
   }

   public int c() {
      return this.j ? this.h : this.i;
   }

   public int d() {
      return this.j ? this.i : this.h;
   }

   public int e() {
      return this.k ? 1 : (this.h == 1 ? this.i : (this.i == 1 ? this.h : this.h * this.i));
   }

   public boolean l() {
      return this.k;
   }

   public boolean m() {
      return this.k ? true : (this.j ? this.h < 2 : this.i < 2);
   }

   public boolean n() {
      return this.k ? true : (this.j ? this.i < 2 : this.h < 2);
   }

   public zagu a(int var1, int var2) {
      if (this.k) {
         return this.s;
      } else if (this.q) {
         return this.a;
      } else {
         if (this.j) {
            if (var2 == this.l) {
               var1 += this.m;
               if (var1 >= this.n && var1 <= this.o) {
                  return this.g[var1];
               }
            }
         } else if (var1 == this.l) {
            var2 += this.m;
            if (var2 >= this.n && var2 <= this.o) {
               return this.g[var2];
            }
         }

         return this.a;
      }
   }

   public void f() {
      if (!this.k && !this.q) {
         this.r = this.n - 1;
      }
   }

   public boolean b(int var1, int var2) {
      if (!this.k && !this.q) {
         if (this.j) {
            var1 += this.m;
            if (var1 <= this.n) {
               if (this.p) {
                  this.r = this.n;
                  this.s = this.g[this.r];
                  return true;
               }

               if (this.r == this.n) {
                  return true;
               }

               this.r = this.n - 1;
            } else {
               if (var1 == this.r && this.r <= this.o && var2 < this.l) {
                  return true;
               }

               this.r = var1;
               if (var2 <= this.l) {
                  --this.r;
               }
            }
         } else {
            if (var1 > this.l) {
               this.r = this.o;
               return false;
            }

            if (var1 < this.l) {
               if (this.p) {
                  this.r = this.n;
                  this.s = this.g[this.r];
                  return true;
               }

               if (this.r == this.n) {
                  return true;
               }

               this.r = this.n - 1;
            } else {
               var2 += this.m;
               if (var2 <= this.n) {
                  if (this.p) {
                     this.r = this.n;
                     this.s = this.g[this.r];
                     return true;
                  }

                  if (this.r == this.n) {
                     return true;
                  }

                  this.r = this.n - 1;
               } else {
                  if (var2 == this.r && this.r <= this.o) {
                     return true;
                  }

                  this.r = var2 - 1;
               }
            }
         }

         return this.g();
      } else {
         return false;
      }
   }

   public boolean a(int var1) {
      if (!this.k && !this.q) {
         int var2;
         int var3;
         if (this.j) {
            var3 = var1 % this.i;
            var2 = var1 / this.i;
         } else {
            var3 = var1 % this.h;
            var2 = var1 / this.h;
         }

         return this.b(var2, var3);
      } else {
         return false;
      }
   }

   public boolean g() {
      if (!this.k && !this.q) {
         ++this.r;
         if (this.r > this.o) {
            return false;
         } else {
            this.s = this.g[this.r];
            if (!a(this.s, this.a)) {
               return true;
            } else {
               do {
                  ++this.r;
                  if (this.r > this.o) {
                     return false;
                  }

                  this.s = this.g[this.r];
               } while(a(this.s, this.a));

               return true;
            }
         }
      } else {
         return false;
      }
   }

   public zagu h() {
      if (this.s.b() == 13) {
         zzh var1 = (zzh)this.s;
         if (var1.k().c() == 2) {
            this.s = var1.k().n();
            this.g[this.r] = this.s;
         }
      }

      return this.s;
   }

   public int i() {
      return this.j ? this.r - this.m : this.l;
   }

   public int j() {
      return this.j ? this.l : this.r - this.m;
   }

   public int k() {
      return this.j ? (this.r - this.m) * this.i + this.l : this.l * this.h + (this.r - this.m);
   }

   public zahn b(int var1) {
      if (this.j) {
         var1 += this.m;
         if (this.i > 1) {
            return (zahn)(var1 >= this.n && var1 <= this.o && !a(this.g[var1], this.a) ? new zaxh(this.g[var1], this.a, this.b, 1, this.i, 0, this.l, -1, -1, this.c, this.d) : new zawz(this.a, this.b, 1, this.i));
         } else {
            zagu var2;
            if (var1 >= this.n && var1 <= this.o) {
               var2 = this.g[var1];
            } else {
               var2 = this.a;
            }

            return new zaya(var2, this.b);
         }
      } else {
         return (zahn)(var1 != this.l && this.i != 1 ? new zawz(this.a, this.b, 1, this.h) : this);
      }
   }

   public zahn c(int var1) {
      if (this.j) {
         return (zahn)(var1 != this.l && this.i != 1 ? new zawz(this.a, this.b, 1, this.h) : this);
      } else {
         var1 += this.m;
         if (this.i > 1) {
            return (zahn)(var1 >= this.n && var1 <= this.o && !a(this.g[var1], this.a) ? new zaxh(this.g[var1], this.a, this.b, this.i, 1, this.l, 0, -1, -1, this.c, this.d) : new zawz(this.a, this.b, 1, this.i));
         } else {
            zagu var2;
            if (var1 >= this.n && var1 <= this.o) {
               var2 = this.g[var1];
            } else {
               var2 = this.a;
            }

            return new zaya(var2, this.b);
         }
      }
   }

   public boolean a(zagu var1) {
      return a(var1, this.k ? this.s : this.a);
   }

   public void a(zaay var1) {
      if (this.c || this.d) {
         if (this.j) {
            if (this.d && var1.h != this.f) {
               this.l -= var1.h - this.f;
               this.f = var1.h;
            }

            if (this.c && var1.g != this.e) {
               this.m += var1.g - this.e;
               this.e = var1.g;
            }
         } else {
            if (this.c && var1.g != this.e) {
               this.l -= var1.g - this.e;
               this.e = var1.g;
            }

            if (this.d && var1.h != this.f) {
               this.m += var1.h - this.f;
               this.f = var1.h;
            }
         }

         this.E();
      }
   }

   public boolean q() {
      return this.p;
   }

   public int r() {
      if (!this.p) {
         this.C();
      }

      return this.q ? -1 : (this.j ? this.n - this.m : this.l);
   }

   public int s() {
      if (!this.p) {
         this.C();
      }

      return this.q ? -1 : (this.j ? this.o - this.m : this.l);
   }

   public int t() {
      if (!this.p) {
         this.C();
      }

      return this.q ? -1 : (this.j ? this.l : this.n - this.m);
   }

   public int u() {
      if (!this.p) {
         this.C();
      }

      return this.q ? -1 : (this.j ? this.l : this.o - this.m);
   }

   public boolean a(zaay var1, int[] var2) {
      int var3;
      int var4;
      if (this.j) {
         if (this.d) {
            var2[1] = Math.max(0, this.l - var1.l.EndColumn + this.f);
            var2[3] = Math.min(var1.l.f() + this.i - 1, this.l - var1.l.StartColumn + this.f);
            if (var2[1] > var2[3]) {
               return false;
            }
         } else {
            if (this.l < 0 || this.l >= this.i) {
               return false;
            }

            var2[1] = this.l;
            var2[3] = this.l;
         }

         if (!this.c) {
            if (!this.p) {
               this.C();
            }

            if (this.q) {
               return false;
            } else {
               var2[0] = this.n - this.m;
               var2[2] = this.o - this.m;
               return true;
            }
         } else {
            var3 = Math.max(0, this.m + var1.l.StartRow - this.e);
            var4 = Math.min(this.g.length, this.m + var1.l.EndRow - this.e + this.h);
            if (var3 >= var4) {
               return false;
            } else {
               while(a(this.g[var3], this.a)) {
                  ++var3;
                  if (var3 == var4) {
                     if (!this.p) {
                        this.p = true;
                        this.D();
                     }

                     return false;
                  }
               }

               var2[0] = var3 - this.m;
               --var4;
               if (var3 < var4) {
                  do {
                     if (!a(this.g[var4], this.a)) {
                        var2[2] = var4 - this.m;
                        return true;
                     }

                     --var4;
                  } while(var4 != var3);
               }

               var2[2] = var2[0];
               return true;
            }
         }
      } else {
         if (this.c) {
            var2[0] = Math.max(0, this.l - var1.l.EndRow + this.e);
            var2[2] = Math.min(var1.l.e() + this.i - 1, this.l - var1.l.StartRow + this.e);
            if (var2[0] > var2[2]) {
               return false;
            }
         } else {
            if (this.l < 0 || this.l >= this.i) {
               return false;
            }

            var2[0] = this.l;
            var2[2] = this.l;
         }

         if (!this.d) {
            if (!this.p) {
               this.C();
            }

            if (this.q) {
               return false;
            } else {
               var2[1] = this.n - this.m;
               var2[3] = this.o - this.m;
               return true;
            }
         } else {
            var3 = Math.max(0, this.m + var1.l.StartColumn - this.f);
            var4 = Math.min(this.g.length, this.m + var1.l.EndColumn - this.f + this.h);
            if (var3 >= var4) {
               return false;
            } else {
               while(a(this.g[var3], this.a)) {
                  ++var3;
                  if (var3 == var4) {
                     if (!this.p) {
                        this.p = true;
                        this.D();
                     }

                     return false;
                  }
               }

               var2[1] = var3 - this.m;
               --var4;
               if (var3 < var4) {
                  do {
                     if (!a(this.g[var4], this.a)) {
                        var2[3] = var4 - this.m;
                        return true;
                     }

                     --var4;
                  } while(var4 != var3);
               }

               var2[3] = var2[1];
               return true;
            }
         }
      }
   }

   public boolean b(zaay var1, int[] var2) {
      int[] var3 = new int[4];
      if (this.a(var1, var3)) {
         int var4 = this.j ? this.i : this.h;
         if (this.d) {
            var4 += var1.l.f() - 1;
         }

         var2[0] = var3[0] * var4 + var3[1];
         var2[1] = var3[2] * var4 + var3[3];
         return true;
      } else {
         return false;
      }
   }

   private void C() {
      this.p = true;

      while(true) {
         if (!a(this.g[this.n], this.a)) {
            if (this.n < this.o) {
               while(a(this.g[this.o], this.a)) {
                  --this.o;
                  if (this.n == this.o) {
                     this.s = this.g[this.n];
                     if (a(this.s, this.a)) {
                        this.D();
                     }
                  }
               }
            }
            break;
         }

         ++this.n;
         if (this.n > this.o) {
            this.D();
            break;
         }
      }

   }

   private void D() {
      this.q = true;
      this.n = -1;
      this.o = -1;
   }

   private void E() {
      this.r = this.m - 1;
      this.p = false;
      this.q = false;
      if (this.l >= 0 && this.l < this.i && this.m < this.h && this.m > -this.h) {
         if (!this.k && this.m != this.g.length - 1) {
            if (this.m + this.h == 1) {
               this.r = 0;
            }
         } else {
            this.r = this.m;
         }

         if (this.r >= this.m) {
            this.p = true;
            this.s = this.g[this.r];
            if (a(this.s, this.a)) {
               this.D();
            } else {
               this.n = this.r;
               this.o = this.r;
            }
         } else {
            this.n = Math.max(0, this.m);
            this.o = Math.min(this.g.length, this.m + this.h) - 1;
         }
      } else {
         this.p = true;
         this.D();
      }

   }
}
